home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 579 < prev    next >
Internet Message Format  |  1996-08-06  |  3KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c,comp.std.c
  4. Subject: Re: atexit() internals under Unix
  5. Date: Sat, 16 Mar 96 21:21:58 GMT
  6. Organization: none
  7. Distribution: world
  8. Message-ID: <827011318snz@genesis.demon.co.uk>
  9. References: <4icqbm$pk9@fnnews.fnal.gov>
  10. Reply-To: fred@genesis.demon.co.uk
  11. X-NNTP-Posting-Host: genesis.demon.co.uk
  12. X-Newsreader: Demon Internet Simple News v1.27
  13. X-Mail2News-Path: genesis.demon.co.uk
  14.  
  15. In article <4icqbm$pk9@fnnews.fnal.gov> berg@fsui01.fnal.gov "David Berg" writes:
  16.  
  17. >I have a some questions regarding ANSI C in a Unix (or POSIX) context.
  18. >They all relate to exit handling. I don't have a copy of the ANSI C
  19. >standard, nor have I been able to find more than cursory explanations
  20. >in other reference sources.
  21. >
  22. >1. Suppose a process registers an exit handler with atexit().  The exit
  23. >   handler, in turn, calls some application library routines, which call
  24. >   others that are also called from the mainline of the program. Leaving
  25. >   the issue of re-entrancy aside, is there any general way (eg, a system
  26. >   service call) by which the function can determine that it was called
  27. >   in the context of an exit handler?
  28.  
  29. No, but this is easy to determine using an auxiliary/wrapper function.
  30. Register the wrapper function which sets a status flag or calls the
  31. work function with a suitable argument.
  32.  
  33. >  Can it access the exit status with which exit() was called?
  34.  
  35. No.
  36.  
  37. >2. Same as above, except the process registers a signal handler with
  38. >   sigaction(). Can a lower level function determine that it was called
  39. >   in the context of a signal handler?
  40.  
  41. Not as far as I am aware. This is a question for comp.unix.programmer.
  42.  
  43. >What if the signal handler calls exit()?
  44.  
  45. That is illegal where the signal was generated from an asynchronous
  46. event (i.e. other than through calling raise() or abort()). Where legal
  47. exit() acts just as it does when called outside a signal handler.
  48.  
  49. >3. Suppose the process now forks. From experimentation, it appears that
  50. >   exit handlers, like signal handlers, are inherited by the child. Is
  51. >   this behavior standard (though beyond the scope of ANSI), or at least
  52. >   conventional?
  53.  
  54. The handlers are inherited, pending signals are not. Again this is a
  55. topic for comp.unix.programmer.
  56.  
  57. >4. If an exit handler calls exit(), is the handler called recursively? Or
  58. >   has it been unregistered before it is invoked? (Again, it would appear
  59. >   from experimentation that it is indeed unregistered.)
  60.  
  61. It is illegal (i.e. results in undefined behaviour) for a program to call
  62. exit() more than once.
  63.  
  64. -- 
  65. -----------------------------------------
  66. Lawrence Kirby | fred@genesis.demon.co.uk
  67. Wilts, England | 70734.126@compuserve.com
  68. -----------------------------------------
  69.